package com.nijie.library.controller.sys;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nijie.library.POJO.Message;
import com.nijie.library.POJO.modelPOJO.User;
import com.nijie.library.service.sys.SysUserSvc;


@Controller
@RequestMapping("sys")
public class YsyCtlr {
    @Autowired
    private SysUserSvc sysUserSvc;

    @RequestMapping("getRegisterPage")
    public String getRegisterPage() {
        return "views/sys/register";
    }

    @RequestMapping("getLoginPage")
    public String getLoginPage() {
        return "views/sys/login";
    }
    @RequestMapping("getMainPage")
    public String getMainPage() {
        return "views/main";
    }
    @RequestMapping("login")
    @ResponseBody
    public Message<Object> login(User user,HttpSession session){
		Message<Object> message = new Message<Object>();
		List<User> userList = sysUserSvc.login(user);
		if(userList.size()>0){
			message.setCode("103");
			message.setMsg("登录成功");
			message.setData(userList.get(0));
			session.setAttribute("userId", userList.get(0).getId());
			session.setAttribute("roleId", userList.get(0).getRoleId());
		}else{
			message.setCode("104");
			message.setMsg("登录失败");
		}
		return message;
    }
}
